/**
 * @description: 分类管理模块相关的接口
 */
import request from '@/utils/request'
import type {
  CategoryResponseData,
  AttrResponseData,
  Attr,
} from '@/api/product/attr/type'

/**
 * 属性管理模块接口地址
 */
enum API {
  // 获取一级分类数据
  GET_CATEGORY1_URL = '/admin/product/getCategory1',
  // 获取二级分类数据
  GET_CATEGORY2_URL = '/admin/product/getCategory2/',
  // 获取三级分类数据
  GET_CATEGORY3_URL = '/admin/product/getCategory3/',
  // 获取对应分类下已有的属性与属性值列表
  GET_ATTR_LIST_URL = '/admin/product/attrInfoList/',
  // 添加或修改属性与属性值
  ADD_OR_UPDATE_ATTR_URL = '/admin/product/saveAttrInfo',
  // 删除属性与属性值
  DELETE_ATTR_URL = '/admin/product/deleteAttr/',
}

/**
 * 获取一级分类数据
 */
export const reqGetCategory1 = () => {
  return request.get<any, CategoryResponseData>(API.GET_CATEGORY1_URL)
}

/**
 * 获取二级分类数据
 */
export const reqGetCategory2 = (category1Id: number | string) => {
  return request.get<any, CategoryResponseData>(
    API.GET_CATEGORY2_URL + category1Id,
  )
}

/**
 * 获取三级分类数据
 */
export const reqGetCategory3 = (category2Id: number | string) => {
  return request.get<any, CategoryResponseData>(
    API.GET_CATEGORY3_URL + category2Id,
  )
}

/**
 * 获取对应分类下已有的属性与属性值列表
 */
export const reqGetAttrList = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string,
) => {
  return request.get<any, AttrResponseData>(
    API.GET_ATTR_LIST_URL + `${category1Id}/${category2Id}/${category3Id}`,
  )
}

/**
 * 添加或修改属性与属性值的接口
 */
export const reqAddOrUpdateAttr = (data: Attr) => {
  return request.post<any, any>(API.ADD_OR_UPDATE_ATTR_URL, data)
}

/**
 * 删除属性与属性值
 */
export const reqDeleteAttr = (attrId: number | string) => {
  return request.delete<any, any>(API.DELETE_ATTR_URL + attrId)
}
